<extend name="Public/base"/>
<block name="content">
<h3 class="col-md-3">歌曲管理</h3>
<i>支持二级目录,目录对应曲风,不存在自动创建！</i>
<form id="import-form" method="post" class="form-horizontal" action="<{:U('songs/fileImport')}>"> 
<div class="row">	
	<div class="col-lg-12">
		
		<div class="panel panel-default">
	        <div class="panel-heading">
	            设置参数
	            <a class="pull-right" title="" data-toggle="tooltip" data-perform="panel-collapse" href="javascript:void(0);" data-original-title="显示/隐藏">
				<em class="fa fa-minus"></em>
				</a>
	        </div>
	     	<div class="panel-body">     		
	     		<div class="col-lg-4">      
		    		<div class="form-group">	
		    			<label class="col-sm-3 control-label">所属艺术家</label>
		    			<div class="col-sm-9">
		    				<div class="input-group">
		    					<input type="text" class="hide" id="artist-id" name="artist_id" value="0">	
		    					<input type="text" class="form-control" id="artist-name" name="artist_name"  value="<{$data.artist_name|default='佚名'}>">	
								<a href="#" class="input-group-addon ajax-find" rel="artist">
		                         	<span class="fa-search fa"></span>
		                    	</a>
		                    </div>
		    			</div>	
		            </div>
		            					
					<div class="form-group">	
		    			<label class="col-sm-3 control-label">所属专辑</label>
		    			<div class="col-sm-9">
		   					<div class="input-group">
		    					<input type="text"  class="hide" name="album_id" id="album-id" value="0">
		    					<input type="text" class="form-control"  name="album_name" id="album-name" value="单曲">
								<a href="#" class="input-group-addon ajax-find" rel="album">
		                         	<span class="fa-search fa"></span>
		                    	</a>
		                    </div>
		    			</div>	
		    		</div>
		    		
		    		<div class="form-group">		
		    			<label class="col-sm-3 control-label">所属用户</label>
		    			<div class="col-sm-3 controls">	
		    				<input type="text" class="form-control"  name="up_uid"  value="">	                   
		    			</div>	
		    			<p class="help-block col-sm-6">填写会员ID</p>	
		    	    </div>	
					     
	         	</div>
	         	
	         	<div class="col-lg-4">
	              	<div class="form-group">						
		    			<label class="col-sm-3 control-label ">试听次数</label>
		    			<div class="col-sm-4 controls">
		    				<input type="text" class="form-control"  value="200-1000" name="listens">
		    			</div>
		    			<span class="help-block">整数/随机数：格式 1-200</span>
		    		</div>
		    		
		    		<div class="form-group">						
		    			<label class="col-sm-3 control-label ">下载次数</label>
		    			<div class="col-sm-4 controls">
		    				<input type="text" class="form-control"  value="200-1000" name="download">
		    			</div>
		    			<span class="help-block">整数/随机数：格式 1-200</span>
		    		</div>
		    		
		    		<div class="form-group">						
		    			<label class="col-sm-3 control-label ">下载积分</label>
		    			<div class="col-sm-4 controls">
		    				<input type="text" class="form-control"  value="0" name="gold">
		    			</div>
		    		</div>
		    		
		    		<div class="form-group">						
		    			<label class="col-sm-3 control-label ">评分</label>
		    			<div class="col-sm-4 controls">
		    				<input type="text" class="form-control"  value="6" name="rater">
		    			</div>
		    			<span class="help-block"></span>
		    		</div>
	   			</div>	   			   		
	   			<div class="col-lg-4">
	   				<div class="form-group">						
		    			<label class="col-sm-3 control-label ">下载目录</label>
		    			<div class="col-sm-4 controls">
		    				<input type="text" class="form-control"  value="" name="down_dir">
		    			</div>
		    			<span class="help-block">格式Music/listen/ 留空和试听地址相同</span>
		    		</div>
		    		
		    		<div class="form-group">						
		    			<label class="col-sm-3 control-label ">下载音质</label>
		    			<div class="col-sm-4 controls">
		    				<input type="text" class="form-control"  value="320k" name="down_bit">
		    			</div>
		    			<span class="help-block"></span>
		    		</div>
	   				
	   				<div class="form-group">		
						<label class="col-sm-3 control-label">推荐</label>
		    			<div class="col-sm-9 controls">
							<input class="hide" name="recommend" value="0">
							<div  class="switch-wrapper">
								<span class="switch-enable">是</span>
								<span class="switch-disable selected">否</span>	
							</div>
		                </div>	
		    	    </div>		    	    
					     
	         	</div>
	   		
	   		</div>  
	   </div>	   
	</div>
</div>


<div class="row">
    <div class="col-lg-12">
    	<div class="panel panel-default">
       		<div class="panel-heading ">批量导入歌曲
       			<a id="createGenreDir" class="btn btn-labeled btn-success " href="javascript:;">批量创建曲风目录</a>
       			<div class="btn-group pull-right">
       				<a class="btn btn-labeled" href="<{:U('songs/bulkImport',array('type'=>'refresh'))}>">刷新</a>
	       			<a id="import" class="btn btn-labeled btn-success " href="javascript:;">全部导入</a>
	         	</div>			
       		</div>
    		<div class="table-responsive">
    			   															   
			        <table class="table table-striped table-bordered table-hover"> 
			            <thead>
			            	<tr class="form-inline">
							</tr>
			                <tr>
			               		<th style="width: 5%" class="check-all">
                          		<div data-toggle="tooltip" data-title="全选" class="checkbox c-checkbox">
                             		<label>
                                		<input type="checkbox" checked="chedked" >
                                		<span class="fa fa-check"></span>
                             		</label>
                          		</div>
                       			</th> 
			                    <th>文件名称</th>
			                    <th>二级目录/曲风</th>
			                    <th>文件大小</th>
			                    <th>状态</th>
			                    <th>操作</th>
			                </tr>
			            </thead>
			            <tbody>			            
			            	<empty name="info">	            		 
			                	<volist name="list" id="vo">
			                    <tr>
		                       		<td>
		                          		<div class="checkbox c-checkbox">
		                             		<label>
		                                	<input type="checkbox" class="ids" checked="chedked"  value="<{$i}>" name="tables[]">
		                                	<span class="fa fa-check"></span>
		                             		</label>
		                          		</div>
		                       		</td>		                       			                    	
			                        <td><{$vo['fileName']|file_name_convert}></td>
			                        <td><{$vo['dirName']}></td>
			                        <td><{$vo['path']|get_filesize}></td>			                       
			                        <td class="info">未导入</td>
			                        <td class="action">
			                            <a class="db-import" href="<{:U('import?time='.$data['time'])}>">导入</a>			     
			                        </td>
			                    </tr>
			                	</volist>
			                <else />
			            		<td colspan="6" class="text-center"><{$info}></td>
			            	</empty>
			            </tbody>
			        </table>
		       
    		</div> 		
    	</div>
	</div>
</div>
</form>
</block>

<block name="script">
<script type="text/javascript"  src="__JS__/other.js"></script>
<script type="text/javascript">
	var findUrl="<{:U('Ajax/findData')}>";
	highlight_subnav("<{:U('Songs/bulkImport')}>");	
    (function($){
        var $form = $("#import-form"), $export = $("#import"), tables;
        $export.click(function(){
            $export.parent().children().addClass("disabled");
            $export.html("正在发送导入请求...");
            $.post(
                $form.attr("action"),
                $form.serialize(),
                function(data){
                    if(data.status){
                        tables = data.tables;
                        $export.html(data.info + "开始导入，请不要关闭本页面！");
                        backup(data.tab);
                        window.onbeforeunload = function(){ return "正在导入数据，请不要关闭！" }
                    } else {
                        topAlert(data.info,'alert-error');
                        $export.parent().children().removeClass("disabled");
                        $export.html("全部导入");
                    }
                },
                "json"
            );
            return false;
        });

        function backup(tab, status){
        	//alert(tab);
            status && showmsg(tab.id, "开始导入...");
            $.get($form.attr("action"), tab, function(data){
                if(data.status){
                    showmsg(tab.id, data.info);
                    if(!$.isPlainObject(data.tab)){
                        $export.parent().children().removeClass("disabled");
                        $export.remove();
                        window.onbeforeunload = function(){ return null }
                        return;
                    }
                    backup(data.tab, tab.id != data.tab.id);
                } else {
                    topAlert(data.info,'alert-error');
                    $export.parent().children().removeClass("disabled");
                    $export.html("立即导入");
                }
            }, "json");

        }

        function showmsg(id, msg){
            $form.find("input[value=" + tables[id] + "]").closest("tr").find(".info").html(msg);
        }
        
       	$('#createGenreDir').click(function(){
            $.post(
                "<{:U('Songs/createGenreDir')}>",
                function(data){
					topAlert(data.info,'success');
                },
                "json"
            );
        });
    })(jQuery);
</script>

</block>	


